
const path = require('path');
const fs = require('fs');
let md = require('markdown-it')();

let tplPath = path.join(__dirname, 'tpl.html');
let mdPath = path.join(__dirname, 'demo.md');
let targetPath = path.join(__dirname, 'demo.html');

fs.readFile(tplPath, 'utf8', (err, _data) => {
    if (err) {
        throw err;
    }
    let mdTranslate = null;
    fs.readFile(mdPath, 'utf8', (err, _mdStr) => {
        if (err) {
            throw err;
        }
        mdTranslate = md.render(_mdStr);
        let _tplReplace = _data.replace('{content}', mdTranslate);
        fs.writeFile(targetPath, _tplReplace, 'utf8', (err) => {
            if (err) throw err;
            console.log('文件已被保存');
        });
    });
});

// var result = md.render('# markdown-it rulezz!');
// console.log(result);
